package com.ficus.road.maintain;

import com.ficus.road.maintain.config.DiseaseConfig;
import com.ficus.road.maintain.util.AliyunOSSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;

/**
 * Created by jinbiao.he on 2021/04/05.
 */
@RestController
@SpringBootApplication
//@EnableCaching
public class RoadMaintainApplication {


    @Autowired
    private DiseaseConfig diseaseConfig;

    @Autowired
    private AliyunOSSUtil aliyunOSSUtil;

    public static void main(String[] args) {
        SpringApplication.run(RoadMaintainApplication.class, args);

        System.out.println("                                     \n" +
                "   __    ________    __      __      \n" +
                " /'__`\\ /\\_____  \\ /'__`\\  /'_ `\\    \n" +
                "/\\ \\/\\ \\\\/___//'/'/\\ \\/\\ \\/\\ \\L\\ \\   \n" +
                "\\ \\ \\ \\ \\   /' /' \\ \\ \\ \\ \\ \\___, \\  \n" +
                " \\ \\ \\_\\ \\/' /'    \\ \\ \\_\\ \\/__,/\\ \\ \n" +
                "  \\ \\____/\\_/       \\ \\____/    \\ \\_\\\n" +
                "   \\/___/\\//         \\/___/      \\/_/\n" +
                "                                     \n" +
                "                                    ");


    }

    /**
     * 本地图片转换成base64字符串
     *
     * @param imgFile 图片本地路径
     * @return
     * @author ZHANGJL
     * @dateTime 2018-02-23 14:40:46
     */
    public static String ImageToBase64ByLocal(String imgFile) {// 将图片文件转化为字节数组字符串，并对其进行Base64编码处理


        InputStream in = null;
        byte[] data = null;

        // 读取图片字节数组
        try {
            in = new FileInputStream(imgFile);

            data = new byte[in.available()];
            in.read(data);
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        // 对字节数组Base64编码
        Base64.Encoder encoder = Base64.getEncoder();
        return encoder.encodeToString(data);// 返回Base64编码过的字节数组字符串
    }

    @GetMapping("/")
    public String home() {
//        Map<String, String> roadCompanyMap = roadCompanyConfig.getMap();
//        String url = "C:\\Users\\hao.zhou1\\Desktop\\图片3.png";
//        String str = ImageToBase64ByLocal(url);
//
//        FileUploadParam param = new FileUploadParam();
//        param.setFileName("图片1.png");
//        param.setFileType("png");
//        param.setData(str);
//        AliyunOssResult upload = aliyunOSSUtil.upload(param);
//        System.out.println(upload.getUrl());
        return "Hello road maintain!";
    }

}
